use moss_expand::derive::{from_attrs, from_meta, syn_parse};
use proc_macro::TokenStream;
use syn::parse_macro_input;

macro_rules! convert_expand_result {
    ($e:expr) => {
        match $e {
            Ok(val) => val.into(),
            Err(err) => err.into_compile_error().into(),
        }
    };
}

#[proc_macro_derive(FromMeta, attributes(name, strip))]
pub fn derive_from_meta(input: TokenStream) -> TokenStream {
    let expand_result = from_meta::expand(&parse_macro_input!(input));
    convert_expand_result!(expand_result)
}

#[proc_macro_derive(FromAttrs)]
pub fn derive_from_attrs(input: TokenStream) -> TokenStream {
    let expand_result = from_attrs::expand(&parse_macro_input!(input));
    convert_expand_result!(expand_result)
}

#[proc_macro_derive(SynParse)]
pub fn derive_syn_parse(input: TokenStream) -> TokenStream {
    let expand_result = syn_parse::expand(&parse_macro_input!(input));
    convert_expand_result!(expand_result)
}
